//
//  SFGroupTableViewCell.m
//  Test
//
//  Created by xueshan1 on 2019/3/20.
//  Copyright © 2019 xueshan1. All rights reserved.
//

#import "SFGroupTableViewCell.h"

@interface SFGroupTableViewCell ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation SFGroupTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.contentView.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        
        _tableView = [[UITableView alloc]initWithFrame:CGRectInset(self.bounds, 15, 0) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.scrollEnabled = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

        [self.contentView addSubview:_tableView];
        _tableView.layer.cornerRadius = 6;
        _tableView.layer.masksToBounds = YES;
        
        UIView *subLayer=[UIView new];
        CGRect fixframe = _tableView.frame;
        subLayer.frame = fixframe;
        subLayer.layer.cornerRadius= 10;
        subLayer.layer.backgroundColor=[[UIColor greenColor] colorWithAlphaComponent:0.8].CGColor;
        subLayer.layer.masksToBounds=NO;
        subLayer.layer.shadowColor = [UIColor lightGrayColor].CGColor;//shadowColor阴影颜色
        subLayer.layer.shadowOffset = CGSizeMake(0,2);
        subLayer.layer.shadowOpacity = 0.7;
        subLayer.layer.shadowRadius = 5;
        [self.contentView insertSubview:subLayer belowSubview: _tableView];
        subLayer.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
 }

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.cellDelegate && [self.cellDelegate respondsToSelector:@selector(groupTableViewCell:numberOfRowsInSection:)]) {
       return [self.cellDelegate groupTableViewCell:self numberOfRowsInSection:self.tag - 100];
    }
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.cellDelegate && [self.cellDelegate respondsToSelector:@selector(groupTableViewCell:heightForRowAtIndexPath:)]) {
        return [self.cellDelegate groupTableViewCell:self heightForRowAtIndexPath:indexPath];
    }
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    NSLog(@"cell %p", [self.cellDelegate groupTablewViewCell:self cellForRowAtIndexPath:indexPath]);

    if (self.cellDelegate && [self.cellDelegate respondsToSelector:@selector(groupTablewViewCell:cellForRowAtIndexPath:)]) {
       return [self.cellDelegate groupTablewViewCell:self cellForRowAtIndexPath:indexPath];
    }
    return nil;
}
 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if (self.cellDelegate && [self.cellDelegate respondsToSelector:@selector(groupTableViewCell:didSelectedRowAtIndexPath:)]) {
        [self.cellDelegate groupTableViewCell:self didSelectedRowAtIndexPath:indexPath];
    }
    
}




@end
